//
//  UserStatus.swift
//  flowerpot
//
//  Created by fyname on 16/1/20.
//  Copyright © 2016年 senhe. All rights reserved.
//

import Foundation
var usDict = Dictionary<String, String>()
//用户在线状态，上线下线
class UserStatus: NSObject {
    
    static func setUserStatus(userStatusDO:UserStatusDO){
        usDict[userStatusDO.userId!] = userStatusDO.userStatus
    }
    
    static func getUserStatus(userId:String)->UserStatusDO{
        let userStatusDO = UserStatusDO()
        for (key , value) in usDict
        {
            print("value=:\(key)")
            if(key == userId){
                userStatusDO.userId = key
                userStatusDO.userStatus = value
            }
        }
        
        return userStatusDO
    }
    
    static func updateUserStatus(userId:String,userStatus:String)->Bool{
        
        var flag = false
        
        if let oldValue =  usDict.updateValue(userStatus, forKey: userId){
            if (userStatus != "" && userStatus != oldValue){
                flag = true
            }
        }
        
        return flag
    }
    
}